//写一个函数实现两个大数相加。
const assert = require('assert')

function add(a ,b){
    let q = []
    let result = ''
    let obj = {}
    let max = ''
    let min = ''
    if(a.length === b.length){
        max = a;
        min = b;
    }else{
        max = a.length > b.length ? a : b
        min = a.length > b.length ? b : a
    }
     
    const len = Math.min(a.length, b.length)
    const dis = max.length  - min.length

    for(let i = len -1 ; i >= 0; i--){
        const res = Number(min[i]) + Number(max[i + dis])
        q.push(res)
    }

    q.forEach((i, index) => {
        let r = i
        if(i > 9){
            obj[index + 1] = 1
            r = Number(String(i)[1])
        }
        r = index in obj ? r+1 : r
        result =  (r + '') + result
    })

    let rest = max.slice(0, dis)
    if(dis in obj){
        rest = rest.slice(0, -1) + (Number(rest[rest.length -1]) + 1)
    }

    result = rest + result



    return result

}

assert(add('123123', '123123') === '246246')
assert(add("943","67") === '1010');
assert(add("10999888999","10999888998") === String(10999888999 + 10999888998));
assert(add("1000","9") === String(1000 + 9));
assert(add("1000","99") === String(1000 + 99));

